<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/sb/js/jquery-1.8.3.js"></script>
    <script>
        $(function(){
            $.ajax({
                url:"/sb/dept/list",//请求地址
                dataType:"json",//返回值格式
                success:function(data){
                    if(data!=''){
                        var tempTrs="";
                        for (var i = 0; i < data.length; i++) {
                            var obj = data[i];
                            tempTrs+="<tr><td>"+obj.DEPTNO+"</td><td>"+obj.DNAME+"</td><td>"+obj.LOC+"</td>" +
                                "<td><a href='update.html?deptNo="+obj.DEPTNO+"'&dname="+obj.DNAME+"><input value='更新' type='button'></a>&nbsp; " +
                                "<input value='删除' type='button' onclick='deleteOne("+obj.DEPTNO+")'> </td></tr>";
                        }
                        $("#tbodyA").append(tempTrs);
                    }
                }
            });
        });

    </script>
</head>
<body>
<center>
    <h1>部门列表</h1>
    <input type="button" value="添加" onclick="insert()">
    <table border="1" width="600px;">
        <thead><td>名称</td><td>位置</td><td>操作</td></thead>
        <tbody id="tbodyA"></tbody>
    </table>
</center>
<script>
    //添加按钮
    function insert() {
        location.href="/sb/html/add.html";
    }
    function deleteOne(deptNo) {
        if(confirm("确定删除吗？")){
            $.get(
                "/sb/dept/deleteOne",
                {deptNo:deptNo},
                function(data) {
                    alert(data.msg);
                    location.href="/sb/html/list.html";
                },
                "json"
            );
        }
    }
</script>
</body>
</html>